﻿var dThinking = $get('dThinking');
var ContactResponse = $get('ContactResponse');

if (ContactResponse != null) {
    HideElement('ContactResponse');
    HideElement('dThinking');
}


function StoreContact() {

    HideElement('dMakeContact');
    HideElement('ContactResponse');
    ShowElement('dThinking');

    var FirstName = $get('FirstName');
    var LastName = $get('LastName');
    var Addr1 = $get('Addr1');
    var Addr2 = $get('Addr2');
    var City = $get('City');
    var State = $get('txtState');
    var Zip = $get('txtZip');
    var Phone = $get('txtPhone');
    var EMail = $get('EMail');
    var Comment = $get('Comment');

    var objCat = new ContactInfo();
    objCat.FirstName = FirstName.value;
    objCat.LastName = LastName.value;
    objCat.Address1 = Addr1.value;
    objCat.Address2 = Addr2.value
    objCat.City = City.value;
    objCat.State = State.value;
    objCat.Zip = Zip.value;
    objCat.phone = Phone.value;
    objCat.Email = EMail.value;
    objCat.Request = Comment.value;

    ContactService.PostContactRequest(objCat, StoreCommentCompleteEvent, StoreCommentErrorEvent);

    return false;
}


function StoreCommentCompleteEvent(result, context) {

    HideElement('dThinking');
    ShowElement('ContactResponse');

    ContactResponse.innerHTML = ContactResponse.innerHTML + '<BR/>' + result;

}

function StoreCommentErrorEvent(result, context) {
    alert('It blew up!');
    if (null != result) {
        alert(result.get_stackTrace());
    }
}

function ShowElement(ElementName) {
    $get(ElementName).style.display = '';
}

function HideElement(ElementName) {
    $get(ElementName).style.display = 'none';
}